package com.xxl.job.admin;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author xuxueli 2018-10-28 00:38:13
 */
@SpringBootApplication
@NacosPropertySource(dataId = "xxl-job-admin.yml",groupId = "xxl-job" ,autoRefreshed = true)
public class XxlJobAdminApplication implements CommandLineRunner {
	@NacosInjected
	private NamingService namingService;

	@Value("${spring.application.name}")
	private String applicationName;

	@Value("${server.port}")
	private Integer serverPort;

	@Value("${nacos.discovery.register.ip}")
	private String nacosAddr;

	public static void main(String[] args) {
        SpringApplication.run(XxlJobAdminApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		namingService.registerInstance(applicationName,nacosAddr,serverPort);
	}
}